package com.overseasShopping.Action;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.overseasShopping.Biz.InformationBiz;
import com.overseasShopping.Biz.UserBiz;
import com.overseasShopping.pojo.Information;
import com.overseasShopping.pojo.User;

public class InformationAction {
	private InformationBiz informationBiz;
	private UserBiz userBiz;
	private String content;
	private String id;
	private int comscript;
	

	public int getComscript() {
		return comscript;
	}

	public void setComscript(int comscript) {
		this.comscript = comscript;
	}

	public UserBiz getUserBiz() {
		return userBiz;
	}

	public void setUserBiz(UserBiz userBiz) {
		this.userBiz = userBiz;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public InformationBiz getInformationBiz() {
		return informationBiz;
	}

	public void setInformationBiz(InformationBiz informationBiz) {
		this.informationBiz = informationBiz;
	}
	public String prexiaoxi(){
		Map<String, Object> session=ActionContext.getContext().getSession();
		User user=(User)session.get("user");
		List<Information> informations = informationBiz.getsendinfobyuid(user);
		if(informations!=null&&informations.size()>0){
			for (Information information : informations) {
				String dontclose=information.getReceiveUser().getDetailUser().getNickName();
				dontclose=information.getSendUser().getDetailUser().getNickName();
			}
		}
		session.put("informations",informations);
		return "toxiaoxi";
	}
	
	public String sendlist(){
		Map<String, Object> session=ActionContext.getContext().getSession();
		User user=(User) session.get("user");
		List<Information> informations = informationBiz.getsendinfobyuid(user);
		if(informations!=null&&informations.size()>0){
			for (Information information : informations) {
				String dontclose=information.getReceiveUser().getDetailUser().getNickName();
				dontclose=information.getSendUser().getDetailUser().getNickName();
			}
		}
		session.put("informations",informations);
		return "tosendlist";
	}
	public String senddetail(){
		Map<String, Object> session=ActionContext.getContext().getSession();
		Information info= ((List<Information>)session.get("informations")).get(comscript-1);
		Information information=informationBiz.getinformation(info.getId());
		information.getReceiveUser().getDetailUser().getNickName();
		int infosize=((List<Information>) session.get("informations")).size();
		session.put("infosize", infosize);
		session.put("comscript", comscript);
		session.put("information", information);
		return "toinfodetail";
	}
	public String recievedetail(){
		Map<String, Object> session=ActionContext.getContext().getSession();
		Information info= ((List<Information>)session.get("informations")).get(comscript-1);
		Information information=informationBiz.getinformation(info.getId());
		information.getSendUser().getDetailUser().getNickName();
		int infosize=((List<Information>) session.get("informations")).size();
		session.put("infosize", infosize);
		session.put("comscript", comscript);
		session.put("information", information);
		return "toinfodetail";
	}
	
	public String receivelist(){
		Map<String, Object> session=ActionContext.getContext().getSession();
		User user=(User) session.get("user");
		List<Information> informations = informationBiz.getreceiveinfobyuid(user);
		if(informations!=null&&informations.size()>0){
			for (Information information : informations) {
				String dontclose=information.getReceiveUser().getDetailUser().getNickName();
				dontclose=information.getSendUser().getDetailUser().getNickName();
			}
		}
		session.put("informations",informations);
		return "toreceivelist";
	}
	public String sendmessage(){
		Map<String, Object> session=ActionContext.getContext().getSession();
		User user=(User)session.get("user");
		String uuuid=user.getUserId();
		User user2=userBiz.getUser(id);
		User u=user2;
		Information info=new Information(new Date(), content, user, user2);
		informationBiz.addinfo(info);
		return "success";
	}
	public String del(){
		Map<String, Object> session=ActionContext.getContext().getSession();
		Information information=(Information) session.get("information");
		information.setInfostatu("del");
		informationBiz.update(information);
		return "tosendlist";
	}
}
